package com.yihu.cms.action;

import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yihu.beans.ArtworkDescription;
import com.yihu.cms.service.ArtworkDescriptionService;

@Controller
public class ArtworkDescriptionController extends BaseController{

	protected final Logger log = LoggerFactory.getLogger(this.getClass());
	
	ArtworkDescriptionService ads = new ArtworkDescriptionService();
	
	@RequestMapping(value = "/ArtworkDescription", method = RequestMethod.POST)
	public @ResponseBody Object create(@Valid @RequestBody ArtworkDescription artworkDescription , BindingResult vResult) {
		int result = ads.add(artworkDescription);
		log.info("result=" + result);
		return getResult(result, null);
	}
	
	@RequestMapping(value = "/ArtworkDescription/{id:\\d+}", method = RequestMethod.GET)
	public @ResponseBody ArtworkDescription getById(@PathVariable("id") int id) {
		log.info("get artwork id=" + id);
		return ads.getById(id);
	}
	
	@RequestMapping(value = "/ArtworkDescription", method = RequestMethod.PUT)
	public @ResponseBody Object update(@Valid @RequestBody ArtworkDescription artworkDescription , BindingResult vResult) {
		int result = ads.update(artworkDescription);
		log.info("result=" + result);
		return getResult(result, null);
	}
	
	@RequestMapping(value = "/ArtworkDescription/{id:\\d+}", method = RequestMethod.DELETE)
	public @ResponseBody Object delete(@PathVariable("id") long id) {
		log.info("del artworkDescription id=" + id);
		int result = ads.del(id);
		log.info("result=" + result);
		return getResult(result, null);
	}
	
}
